// pages/userCenter/pingjiaManager/pingjiaManager.js
const app = getApp();
const request = require('../../../utils/request');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    isShow:false,
    commentList: [],
    page: 1,
    count: 10,
    index: 0,
    key: "",
  },
  getComment(){
    wx.showLoading()
    if(this.data.index == 0){
      var data = {
        page: this.data.page
      }
    }else{
      var data = {
        key: this.data.key,
        page: this.data.page
      }
    }

    request.get('comment_list', data)
      .then(res => {
        wx.hideLoading()
        var content = this.data.commentList.concat(res.data);
        
        this.setData({
          commentList: content,
        })
      })
      .catch(error => {
        wx.showToast({
          icon: 'none',
          title: error.msg && error.msg
        })
      })
      .finally(_ => {
        
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getComment()
  },
  changeTab(e){
    if (e.detail.index == 1){
      this.setData({
        isShow : true,
        index: e.detail.index,
        commentList: []
      })
    }else{
      this.setData({
        isShow : false,
        index: e.detail.index,
        commentList: []
      })
    }
    this.getComment();
  },
  searchKey(e){
    this.setData({
      key: e.detail.value
    })
  },
  search(){
    this.setData({
      commentList: []
    })
    this.getComment();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.page * that.data.count > that.data.commentList.length && that.data.commentList.length > 0) {
      wx.showToast({
        title: '已加载全部数据',
      })
    } else if (that.data.commentList.length > 0) {
      that.data.page = that.data.page + 1;
      that.getComment();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})